package particles;

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Stage;
import flash.display.StageScaleMode;
import flash.display.StageDisplayState;

import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;

import flash.events.MouseEvent;
import flash.events.Event;

class CppRenderer
{
	var model : EngineModel;
	var lastFrameTime : Float;
	
	public function new(model : EngineModel)
	{
		this.model = model;
		
		var stage = flash.Lib.current.stage;
		stage.scaleMode = StageScaleMode.NO_SCALE;
		
		stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
		
		model.time = flash.Lib.getTimer();
		model.mouseX = 0;
		model.mouseY = 0;
		model.width = 800;
		model.height = 600;
	}
	
	function mouseDown(event : MouseEvent)
	{
		var stage = flash.Lib.current.stage;
		
		switch (stage.displayState)
		{
			case StageDisplayState.NORMAL:
				stage.displayState = StageDisplayState.FULL_SCREEN;
			case StageDisplayState.FULL_SCREEN:
				stage.displayState = StageDisplayState.NORMAL;
			default:
		}
	}
	
	public function render()
	{
		model.time = flash.Lib.getTimer();
		trace("FPS: " + Std.int(1000 / (model.time - lastFrameTime)) + " at " + model.particles.length);
		lastFrameTime = model.time;
		
		var mc = flash.Lib.current;
		
		model.width = Std.int(flash.Lib.current.stage.stageWidth);
		model.height = Std.int(flash.Lib.current.stage.stageHeight);
		model.mouseX = Std.int(mc.mouseX);
		model.mouseY = Std.int(mc.mouseY);
		
		mc.graphics.clear();
		mc.graphics.lineStyle(1, 0xff0000, 1);
		for (particle in model.particles)
		{
			mc.graphics.drawRect(particle.x / 2, particle.y / 2, 1, 1);
		}
	}
}
